package jiyun.com.yiyanmeng;

import android.content.Intent;
import android.graphics.Paint;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.widget.NestedScrollView;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.ArrayList;

import adapter.MyFragmentPagerAdapter;
import base.BaseActivity;
import bean.VideoDataBean;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayer;
import fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard;
import jiyun.com.yiyanmeng.http.WrapContentHeightViewPager;
import presenter.VideoDataPresenter;
import view.VideoDataView;

public class VideoDataActivity extends BaseActivity<VideoDataView, VideoDataPresenter> implements VideoDataView, View.OnClickListener {

    private JCVideoPlayerStandard mPlayerListVideo;
    /**  */
    private TextView mTvNameBig;
    /**
     * 已销售
     */
    private TextView mTvSaleNum;
    /**
     * ￥389元
     */
    private TextView mTvPriceBig;
    /**
     * ￥389元
     */
    private TextView mTvPriceBig2;
    /**
     * · 随时观看
     */
    private TextView mTvTip1;
    private TextView mTvName;
    private ImageView mTvDown;
    private TextView mTvPrice;
    private TabLayout mTab;
    private WrapContentHeightViewPager mViewPager;
    private NestedScrollView mScrollView;
    /**
     * 实付金额
     */
    private TextView mTvAmountDesc;
    private TextView mTvTotalPrice;
    /**
     * 确认支付
     */
    private TextView mTvStudy;
    private RelativeLayout mRl3;
    private String id;
    private String name;
    private String class_hour;
    private String jia_ge;
    private String yuan_jia_ge;
    private String pic;
    private ArrayList<Fragment> fragments;
    private MyFragmentPagerAdapter pagerAdapter;

    @Override
    protected void initData() {
        id = getIntent().getStringExtra("id");
        mPresenter.loadData(Integer.parseInt(id));
    }

    @Override
    protected void setListener() {

    }

    public void initView() {
        mPlayerListVideo = (JCVideoPlayerStandard) findViewById(R.id.player_list_video);
        mTvNameBig = (TextView) findViewById(R.id.tv_name_big);
        mTvSaleNum = (TextView) findViewById(R.id.tv_sale_num);
        mTvPriceBig = (TextView) findViewById(R.id.tv_price_big);
        mTvPriceBig2 = (TextView) findViewById(R.id.tv_price_big2);
        mTvTip1 = (TextView) findViewById(R.id.tv_tip1);
        mTvName = (TextView) findViewById(R.id.tv_name);
        mTvDown = (ImageView) findViewById(R.id.tv_down);
        mTvPrice = (TextView) findViewById(R.id.tv_price);
        mTab = (TabLayout) findViewById(R.id.tab);
        mViewPager = (WrapContentHeightViewPager) findViewById(R.id.viewPager);
        mScrollView = (NestedScrollView) findViewById(R.id.scrollView);
        mTvAmountDesc = (TextView) findViewById(R.id.tv_amount_desc);
        mTvTotalPrice = (TextView) findViewById(R.id.tv_total_price);
        mTvStudy = (TextView) findViewById(R.id.tv_study);
        mRl3 = (RelativeLayout) findViewById(R.id.rl3);
        name = getIntent().getStringExtra("name");
        class_hour = getIntent().getStringExtra("class_hour");
        jia_ge = getIntent().getStringExtra("jia_ge");
        yuan_jia_ge = getIntent().getStringExtra("yuan_jia_ge");
        pic = getIntent().getStringExtra("pic");
        mPlayerListVideo.setUp("http://2449.vod.myqcloud.com/2449_22ca37a6ea9011e5acaaf51d105342e3.f20.mp4", JCVideoPlayer.SCREEN_LAYOUT_LIST, " ");
        Glide.with(this).load("http://p.qpic.cn/videoyun/0/2449_43b6f696980311e59ed467f22794e792_1/640").into(mPlayerListVideo.coverImageView);
        mTvName.setText(name);
        mTvNameBig.setText(name);
        mTvPrice.setText("￥" + jia_ge);
        mTvTotalPrice.setText("￥" + jia_ge);
        mTvPriceBig.setText("￥" + jia_ge + "元");
        mTvPriceBig2.setText("￥" + yuan_jia_ge + "元");
        mTvPriceBig2.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);






    }


    @Override
    protected VideoDataPresenter createPresenter() {
        return new VideoDataPresenter();
    }

    @Override
    protected int bindLayoutId() {
        return R.layout.activity_video_data;
    }

    @Override
    public void showToast(String msg) {

    }

    @Override
    public void onSuccess(VideoDataBean dataBean) {
        String xiang = dataBean.getXiang();
        Log.i("xiang",xiang);
        fragments = new ArrayList<>();
        ProgramFragment f1 = new ProgramFragment();
        fragments.add(f1);
        IntroFragment f2 = new IntroFragment();
        Bundle bundle = new Bundle();
        bundle.putString("url",xiang);
        f2.setArguments(bundle);
        fragments.add(f2);
        pagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(), fragments);
        mViewPager.setAdapter(pagerAdapter);
        mTab.setupWithViewPager(mViewPager);
        mTab.getTabAt(0).setText("课程目录");
        mTab.getTabAt(1).setText("课程简介");
        mTvDown.setOnClickListener(this);
        mTvStudy.setOnClickListener(this);



    }

    @Override
    public void onFailed(String str) {

    }



    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
            case R.id.tv_down:

                break;
            case R.id.tv_study:
                Intent intent = new Intent(this,ZhiFuActivity.class);
                intent.putExtra("id",id);
                intent.putExtra("pic",pic);
                intent.putExtra("name",name);
                intent.putExtra("class_hour",class_hour);
                intent.putExtra("jia_ge",jia_ge);
                startActivity(intent);
                break;
        }
    }
}
